package com.qf.android.sport.utils.match;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

/**
 * Created by Administrator on 2016/12/19.
 */

public class DateUtil {
    /**
     * 获得比赛开始时间
     *
     * @param startTime
     * @return
     */
    public static String getTraslateTime(String startTime) {
        SimpleDateFormat format = new SimpleDateFormat("EEE MMM dd hh:mm:ss z yyyy", Locale.ENGLISH);
        try {
            Date date = format.parse(startTime);
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String newDate = sdf.format(date);
            return newDate;
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return "转换失败";
    }

    /**
     * 获得比赛时间
     *
     * @param newDate
     * @return
     */
    public static String getStartTime(String newDate) {
        String[] split = newDate.split(" ");
        String time = split[1];
        String[] split1 = time.split(":");
        String newTime = split1[0] + ":" + split1[1];
        return newTime;
    }

    /**
     * 获得比赛日期
     *
     * @param newDate
     * @return
     */
    public static String getDate(String newDate) {
        String[] split = newDate.split(" ");
        String split1 = split[0];
        String[] split2 = split1.split("-");
        String month = split2[1];
        String date = split2[2];
        return month + "月" + date + "日";
    }

    public static String getWeek(String newDate) {
        String[] split = newDate.split(" ");
        String s = split[0];
        try {
            SimpleDateFormat myFormatter = new SimpleDateFormat("yyyy-MM-dd");
            Date myDate = myFormatter.parse(s);
            SimpleDateFormat formatter = new SimpleDateFormat("E");
            String week = formatter.format(myDate);
            return week;
        } catch (Exception e) {
            System.out.println("错误!");
        }
        return "解析错误";
    }

    /**
     * 获得转换过来的对天数的称谓
     *
     * @param newDate
     * @return
     */
    public static String getTraslate(String newDate) {
        String[] split = newDate.split(" ");
        String s1 = split[0];
        String[] split1 = s1.split("-");
        int date = Integer.parseInt(split1[2]);

        //获取系统当前日期
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        Date curDate = new Date(System.currentTimeMillis());
        String format = dateFormat.format(curDate);
        String[] split2 = format.split(" ");
        String s = split2[0];
        String[] split3 = s.split("-");
        int nowDate = Integer.parseInt(split3[2]);
        int i = nowDate - date;
        switch (i) {
            case 2:
                return "(前天)";
            case 1:
                return "(昨天)";
            case 0:
                return "(今天)";
            case -1:
                return "(明天)";
            case -2:
                return "(后天)";
            default:
                return null;
        }
    }

//    /**
//     * 比赛是否结束
//     *
//     * @param newDate
//     * @return
//     */
//    public static String getIsOver(String newDate) {
//
//        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
//        //获取系统当前日期
//        Date curDate = new Date(System.currentTimeMillis());
//        String format = dateFormat.format(curDate);
//
//        try {
//            Date date1 = dateFormat.parse(newDate);//比赛日期
//            Date date2 = dateFormat.parse(format);//系统当前日期
//            boolean after = date1.after(date2);
//            Log.i("1212", "比赛日期:" + date1 + "系统当前日期:" + date2 +after);
//           if (after){
//               return "1";//未开始比赛
//           }else {
//               return "0";//已结束
//           }
//        } catch (ParseException e) {
//            e.printStackTrace();
//        }
//        return null;
//    }
}
